package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.BalanceDetailDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.BalanceDetail;
import com.zy.pojo.query.bs.BalanceDetailQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.BalanceDetailService;
import com.zy.utils.DateUtil;

@Service("balanceDetailService")
public class BalanceDetailServiceImpl extends BaseServiceImpl<BalanceDetail> implements BalanceDetailService {

	@Autowired
	private BalanceDetailDao balanceDetailDao;

	@Override
	public PageVo pageBalanceDetail(BalanceDetailQuery balanceDetailQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.balanceDetailDao.countBalanceDetail(balanceDetailQuery), this.balanceDetailDao.listBalanceDetail(balanceDetailQuery, start, limit));
	}

	@Override
	public void saveBalanceDetail(BalanceDetail balanceDetail) {
		long time = DateUtil.getTime();
		balanceDetail.setCreateTime(time);
		balanceDetail.setModifyTime(time);
		balanceDetail.setStatus(StatusEnum.NORMAL.getValue());
		this.balanceDetailDao.save(balanceDetail);
	}
	
	@Override
	public void updateBalanceDetail(BalanceDetail balanceDetail) {
		balanceDetail.setModifyTime(DateUtil.getTime());
		this.balanceDetailDao.updateByPrimaryKeySelective(balanceDetail);
	}

	@Override
	public void removeBalanceDetail(long id) {
		try {
			this.balanceDetailDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			BalanceDetail balanceDetail = new BalanceDetail();
			balanceDetail.setId(id);
			balanceDetail.setModifyTime(DateUtil.getTime());
			balanceDetail.setStatus(StatusEnum.DELETE.getValue());
			this.balanceDetailDao.updateByPrimaryKeySelective(balanceDetail);
		}
	}

	@Override
	public void recover(long id) {
		BalanceDetail balanceDetail = new BalanceDetail();
		balanceDetail.setId(id);
		balanceDetail.setModifyTime(DateUtil.getTime());
		balanceDetail.setStatus(StatusEnum.NORMAL.getValue());
		this.balanceDetailDao.updateByPrimaryKeySelective(balanceDetail);
	}

}
